package com.qcnh.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qcnh.entity.Announcement;
import com.qcnh.entity.Payment;
import com.qcnh.service.impl.PaymentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import unil.Result;

import java.util.List;

/**
 * <p>
 * 支付记录表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("payment")//订单功能
public class PaymentController {
    @Autowired
    private PaymentServiceImpl paymentService;

    // 分页模糊查询所有订单
    @GetMapping("selectAllPayments")
    public Result selectAllPayments(@RequestParam(value = "current",defaultValue = "1") Integer current,
                            @RequestParam(value = "size",defaultValue = "10") Integer size,
                            @RequestParam(value = "keyWord",defaultValue = "false") String keyWord) {
        IPage<Payment> Ipage = paymentService.selectAllPayments(current, size, keyWord);
        if(Ipage == null)//判空处理
            return Result.fail(400,"未查询到订单信息",null);
        return Result.ok(200,"订单信息遍历成功",Ipage);
    }

    //添加单个订单
    @PostMapping("addPayment")
    public Result addPayment(@RequestBody Payment payment) {
        if (paymentService.addPayment(payment))
            return Result.ok(200,"添加订单成功",1);
        return Result.fail(400,"添加订单失败",null);
    }

    //根据id集合批量删除订单
    @DeleteMapping("delPaymentsByIdList")
    public Result delPaymentsByIdList(@RequestBody List<Integer> paymentIds){
        if (paymentService.delPaymentsByIdList(paymentIds))
            return Result.ok(200,"删除订单成功",1);
        return Result.fail(400,"删除订单失败",null);
    }
    //根据id修改公告订单
    @PutMapping("updatePayment")
    public Result updatePayments(@RequestBody Payment payment){
        if (paymentService.updatePayment(payment))
            return Result.ok(200,"修改订单成功",1);
        return Result.fail(400,"修改订单失败",null);
    }
}

